<style lang="scss">
.page-wrap{
  position: absolute;
  width: 100%;
  word-wrap: break-word;
  height: 100%;
  overflow-y: scroll;
  background: white;
}
.container{
  font-size: 14px;
  line-height: 1.6;
  /*padding: 10px;*/
  box-sizing: border-box;
}
.wxParse-img{
  width: 100%;
  margin: 0;
}

.new-ul{
  margin-top: 4px;
  padding: 20rpx;
  .new-li{
    width: 100%;
    padding: 8px 0;
    justify-content: space-between;
    .l{
      flex: 1;
      .title{
        color: #222222;
      }
      .create_at{
        color: #06A1FB;
      }
    }
    .r{
      width: 220rpx;
      .thumb{
        width: 200rpx;
        height: 134rpx;
        margin: 0 auto;
        border-radius: 5%;
      }
    }

  }
}

.tip{
  margin-top: 4px;
  padding: 10px;
  text-align: center;
  font-size: 14px;
}

.searchbox{
  padding: 10px;
  display: flex;
  align-items: center;
  .input{
    flex:1;
    display: flex;
    align-items: center;
    border: 1px solid $fun-border-color;
    border-radius: 4px;
    padding-left: 10px;
    .input-ele{
      height: 32px;
      line-height: 32px;
      padding-left: 10px;
    }
  }
  .search-btn{
    padding: 0 10px;
  }
}
</style>
<template>
<div class="page-wrap">

  <div class="searchbox">
    <div class="input">
      <layout-icon type="icon-search" display="inline"></layout-icon>
      <input :placeholder="keyword" class="input-ele" type="text" @input="onInputKeyword" />
    </div>
    <div class="search-btn" @click="onSearch">搜索</div>
  </div>

  <view class="fun-container new-ul bg-white" v-if="list.length>0">
    <navigator class="fun-container-item new-li flex fz-14" v-for="(item,idex) in list" :key="idx" :url="item.client_url+'?id='+item.id">
      <view class="l">
        <view class="title m-b-8 fz-16">{{item.title}}</view>
        <view class="create_at fz-12">{{item.type_title}}</view>
      </view>
      <view class="r">
        <image class="thumb" :src="item.pic" mode="scaleToFill"   />
      </view>
    </navigator>
  </view>
  <view class="tip c6" v-if="isTip">
    没有结果,换个词试试
  </view>
</div>

</template>

<script>

import { pageMixin } from '@/mixins'
import { error, hideLoading, showLoading } from '@/common/fun'
import { fullSearch } from '@/api'
import { Exception } from '@/common/Exception'
import LayoutIcon from '@/components/layout-icon/layout-icon'
export default {
  components: { LayoutIcon },
  mixins: [pageMixin],
  data () {
    return {
      keyword: '民宿',
      list: [],
      isTip: false
    }
  },
  methods: {
    onInputKeyword (e) {
      this.keyword = e.detail.value
      if (!this.keyword) {
        this.isTip = true
      }
    },
    async onSearch () {
      if (!this.keyword) {
        this.isTip = true
        error('关键词不能发票')
        return
      }

      try {
        showLoading()
        const result = await fullSearch({ keyword: this.keyword }).then(res => res.data).catch(err => { throw err })
        if (result.length < 1) {
          this.isTip = true
        } else {
          this.isTip = false
        }
        this.list = result
        hideLoading()
      } catch (e) {
        Exception.handle(e)
      }
    },
    async _init_func () {

    }
  },
  onLoad (options) {
  }
}

</script>
